package com.gaara.test;

import com.gaara.ddp.R;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Point;
import android.view.MotionEvent;

public class TitleScene extends Scene {

	private Bitmap background;

	//开始按钮 
	private MyButton passBtn;
	//竞速按钮 
	private MyButton speedBtn;
	//解密按钮 
	private MyButton decryptBtn;
	//轻松按钮 
	private MyButton easyBtn;

	public TitleScene(MyView view) {
		super(view);

	}



	@Override
	public void onLoadResource() {
		background = BitmapFactory.decodeResource(view.getResources(),R.drawable.titleback);

		passBtn = new MyButton(
				BitmapFactory.decodeResource(view.getResources(),R.drawable.a01), 
				BitmapFactory.decodeResource(view.getResources(),R.drawable.a01a), 
				100,180){

			@Override
			public void onClick() {
				view.setScene(new GameScene(view));
			}			
		};
		
		speedBtn = new MyButton(
				BitmapFactory.decodeResource(view.getResources(),R.drawable.a02), 
				BitmapFactory.decodeResource(view.getResources(),R.drawable.a02a), 
				215,325){
			
			@Override
			public void onClick() {
				
			}			
		};
		
		decryptBtn = new MyButton(
				BitmapFactory.decodeResource(view.getResources(),R.drawable.a03), 
				BitmapFactory.decodeResource(view.getResources(),R.drawable.a03a), 
				410,325){
			
			@Override
			public void onClick() {
				
			}			
		};
		easyBtn = new MyButton(
				BitmapFactory.decodeResource(view.getResources(),R.drawable.a04), 
				BitmapFactory.decodeResource(view.getResources(),R.drawable.a04a), 
				535,180){
			
			@Override
			public void onClick() {
				
			}			
		};
	}



	@Override
	public void onTouchEvent(MotionEvent event) {
		if(passBtn==null){
			System.out.println("Touch按钮为空");
			return;
		}
		passBtn.onTouch(new Point((int)event.getRawX(),(int)event.getRawY()));
		decryptBtn.onTouch(new Point((int)event.getRawX(),(int)event.getRawY()));
		speedBtn.onTouch(new Point((int)event.getRawX(),(int)event.getRawY()));
		easyBtn.onTouch(new Point((int)event.getRawX(),(int)event.getRawY()));
		if(event.getAction() == MotionEvent.ACTION_UP){
			passBtn.isDown = false;
			decryptBtn.isDown = false;
			speedBtn.isDown = false;
			easyBtn.isDown = false;
		}
	}

	@Override
	public void onDraw(Canvas canvas) {
		canvas.drawColor(Color.BLACK);

		canvas.drawBitmap(background, 0, 0,paint);
		if(passBtn==null){
			System.out.println("Draw按钮为空");
			return;
		}
		passBtn.draw(canvas);
		decryptBtn.draw(canvas);
		speedBtn.draw(canvas);
		easyBtn.draw(canvas);
	}

}
